package wsc.mcis.androidDevelpment;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PerformanceArrayAdapter extends ArrayAdapter<RMBLListItem> {
  private final Activity context;
  private final ArrayList<RMBLListItem> items;

  public PerformanceArrayAdapter(Activity context, ArrayList<RMBLListItem> items) {
    super(context, R.layout.list_view_row, items);
    this.context = context;
    this.items = items;
  }

  static class ViewHolder {
    public TextView text;
    public TextView desc;
    public ImageView image;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    
    if (rowView == null) {
      LayoutInflater inflater = context.getLayoutInflater();
      rowView = inflater.inflate(R.layout.list_view_row, null);
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.text = (TextView) rowView.findViewById(R.id.label);
      viewHolder.desc = (TextView) rowView.findViewById(R.id.desc);
      viewHolder.image = (ImageView) rowView.findViewById(R.id.icon);
      rowView.setTag(viewHolder);
    }

    ViewHolder holder = (ViewHolder) rowView.getTag();

    RMBLListItem item = items.get(position);
    
    if (item != null) {
      System.out.println("item not null: " + item.desc);
      holder.text.setText(item.title);
      holder.desc.setText(item.desc);

      // if (position == items.length - 1) {
      // holder.image.setImageResource(R.drawable.addnew);
      // } else {
      holder.image.setImageResource(R.drawable.open);
      // }
    }else{
      System.out.println("item is null");
    }
    return rowView;
  }

  public RMBLListItem getItem(int position) {
    return items.get(position);

  }

}
